This page last changed on Sep 03, 2006 by brian_252.
There are two ways to do this. One is to use OGR/GDAL's tigerpoly.py script. Unfortunately, this sometimes produces bad polygons. I wrote a "how to fix up bad polygons" document as well but its long and very complex (but easy to follow).
I wrote a Java script (using Geotools and JTS) that does, basically, the same thing as the tigerpoly.py script, but is much more robust and does significantly more error checking. This is the recommended load procedure.
It assumes you have your TIGER data in a postgis database and have Java (1.4.2+). Loading TIGER basedata
If you want to see the old (OGR/GDAL/tigerpoly.py) load proceedure see here Loading TIGER polygons tigerpoly.pl.
This process is much faster than the OGR/GDAL process. This takes about 15seconds/county, and the ORG/GDAL takes about 2 minutes/county.
 | TIGER 2005fe error
The tiger2005fe has 2 errors - this will fix it:
update pip set wkb_geometry = 'SRID=1;POINT (-81.30734482864119 28.615619314157783)'::geometry
where module='TGR12117' and polyid = 8709;
update pip set wkb_geometry = 'SRID=1;POINT (-82.06129672922174 39.53997601515791)'::geometry
where module='TGR39009' and polyid = 5710;
update pip set wkb_geometry = 'SRID=1;POINT (-92.5198529528275 36.10732487177976)'::geometry
where module='TGR05089' and polyid = 5052;
update pip set wkb_geometry = 'SRID=1;POINT (-90.5673377761759 29.986304278927115)'::geometry
where module='TGR22095' and polyid = 3980;
update pip set wkb_geometry = 'SRID=1;POINT (-90.38182741292844 29.92608334553412)'::geometry
where module='TGR22089' and polyid = 5204;
update pip set wkb_geometry = 'SRID=1;POINT (-82.32978809930067 31.20110701961316)'::geometry
where module='TGR13299' and polyid = 7263;
update pip set wkb_geometry = 'SRID=1;POINT (-82.84969652715823 30.88904911060222)'::geometry
where module='TGR13065' and polyid = 2222;
update pip set wkb_geometry = 'SRID=1;POINT (-83.42376615233437 33.86629106442862)'::geometry
where module='TGR13219' and polyid = 2164;
- major data error in Guam
update completechain
set wkb_geometry = 'SRID=1;LINESTRING(144.86912 13.499629,144.870032 13.499872,144.870064 13.499926,144.870144 13.500002,144.870512 13.500181,144.870704 13.500268,144.870752 13.500349,144.87072 13.500414,144.870656 13.500452,144.87048 13.500441,144.870128 13.500311,144.869072 13.5)'::geometry
where module = 'TGR66010' and tlid=204580888;
- now make 5157 polygon not have the upper left rectangle in it.
update polychainlink
set polyidl = 31
WHERE module = 'TGR66010' and tlid=204535507;
update polychainlink
set polyidl = 31
WHERE module = 'TGR66010' and tlid=204538093;
update polychainlink
set polyidr = 31
WHERE module = 'TGR66010' and tlid=204552787;
- another major data error in Guam
update completechain
set wkb_geometry = 'SRID=1;LINESTRING (144.802832 13.456777, 144.80264 13.457018999999999, 144.802336 13.457408, 144.80208 13.457727, 144.80192 13.45783)'::geometry
WHERE module = 'TGR66010' and tlid =204581409 ;
update completechain
set wkb_geometry = 'SRID=1;LINESTRING (144.803008 13.457828, 144.802912 13.457507999999999, 144.802864 13.457142999999999, 144.802832 13.456777)'::geometry
WHERE module = 'TGR66010' and tlid =204569152 ;
delete from polychainlink
WHERE module = 'TGR66010' and tlid=204552845;
- another major data error in Guam 2
update completechain
set wkb_geometry = 'SRID=1;LINESTRING (144.714096 13.458386, 144.713936 13.458114, 144.71379199999998 13.457286999999999, 144.714224 13.455983999999999, 144.714352 13.455057)'::geometry
WHERE module = 'TGR66010' and tlid =204553710 ;
update completechain
set wkb_geometry = 'SRID=1;LINESTRING (144.714352 13.455057, 144.714384 13.454868999999999, 144.714 13.454016999999999, 144.71384 13.453848)'::geometry
WHERE module = 'TGR66010' and tlid =204552196 ;
delete from polychainlink
WHERE module = 'TGR66010' and tlid=204540591 ;
- another major data error in Guam 3 (poly1540)
update completechain
set wkb_geometry = 'SRID=1;LINESTRING (144.71384 13.453848,144.71336692401346 13.453342093154188, 144.713088 13.453169)'::geometry
WHERE module = 'TGR66010' and tlid =204552195 ;
update completechain
set wkb_geometry = 'SRID=1;LINESTRING (144.713088 13.453169, 144.712784 13.452979)'::geometry
WHERE module = 'TGR66010' and tlid = 204552189;
delete from polychainlink
WHERE module = 'TGR66010' and tlid=204552193 ; |
 | Finding and correcting errors
The above errors were found by running the polygonization program and then investigating the errors. There are three types:
1. the dataset contains polygons and the TIGER dataset doesnt have PIP (point-in-polygon) for it. Solution - run that group with the "allowMissingPIP" option.
2. the dataset has a polygon with 0 pips. Usually this is an very thin polygon with it PIP just barely outside it. Solution - move the point so its inside the polygon.
3. (only found in Guam) Other error - correct the dataset. |
1. Geotools required a primary key on the table
alter table pip add primary key (ogc_fid);
alter table completechain add primary key (ogc_fid);
alter table polychainlink add primary key (ogc_fid);
2. Create the poly2 table
This is where the polygons will be put:
create table poly2 (the_geom geometry, polyid numeric(10,0), module char(8)) with oids;
insert into geometry_columns values ('','public','poly2','the_geom',2,1,'POLYGON');
3. Download the "tigerpolygonformation.zip" file and unzip it
Available here
This contains the java program (and jars) to run the load. Make sure you have java 1.4.2+ installed.
4. Edit the go.txt script
You may have to edit the postgresql connection string. Use a search-and-replace function.
NOTE: if you are running this on windows, you'll have to replace all the ":" with ";". Use a search-and-replace function.
5. run the go.txt script
6. QA/QC checks
--should be 0 (check for bad polys)
-- see below!!
SELECT module,polyid FROM poly2 WHERE not(isvalid(the_geom)) OR (the_geom isnull);
--make sure all the polygons formed
--- should be 3232
selct count(distinct module) from poly2;
insert into qa_qc
select module,'P',count(*) from poly2 group by module;
SELECT module,count FROM qa_qc where filetype = 'P'
EXCEPT
SELECT county,nfeats FROM counts_txt WHERE type='p';
- should return none! (if it does return something, then there was a load error)
SELECT county,nfeats FROM counts_txt WHERE type='p'
except
SELECT module,count FROM qa_qc where filetype = 'P'
- should return none! (if it does return something, then there was a load error)
 | isvalid() problem
When you execute:
SELECT module,polyid FROM poly2 WHERE not(isvalid(the_geom)) OR (the_geom isnull);
You may get these three polygons:
module | polyid
--------+------
TGR26045 | 1745
TGR33011 | 280
TGR12057 | 4775
These are not actually invalid() - its a bug in the GEOS/JTS isvalid() code. Its been reported and a fix will hopefully make it to PostGIS in the next few releases. |
Hi,
Thanks for your great work! Your instructions are helpful. Unfortunately I can not run java program you have written. I am not java developer and can not solve it myself. Below if the call stack. I have tried it with java 1.4.2 and 1.5.0.
Alexey
start module = TGR06001
loading completechains...
Exception in thread "main" sun.misc.ServiceConfigurationError: org.opengis.referencing.crs.CRSFactory: : java.util.zip.ZipException: Access is denied
at sun.misc.Service.fail(Service.java:129)
at sun.misc.Service.parse(Service.java:209)
at sun.misc.Service.access$100(Service.java:111)
at sun.misc.Service$LazyIterator.hasNext(Service.java:258)
at org.geotools.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:419)
at org.geotools.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:114)
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:221)
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:193)
at org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:90)
at org.geotools.referencing.FactoryFinder.getCRSFactory(FactoryFinder.java:212)
at org.geotools.data.jdbc.referencing.JDBCAuthorityFactory.<init>(JDBCAuthorityFactory.java:60)
at org.geotools.data.postgis.referencing.PostgisAuthorityFactory.<init>(PostgisAuthorityFactory.java:43)
at org.geotools.data.postgis.PostgisDataStore.getPostgisAuthorityFactory(PostgisDataStore.java:965)
at org.geotools.data.postgis.PostgisDataStore.getGeometryAttribute(PostgisDataStore.java:947)
at org.geotools.data.postgis.PostgisDataStore.buildAttributeType(PostgisDataStore.java:878)
at org.geotools.data.jdbc.JDBC1DataStore.buildSchema(JDBC1DataStore.java:1150)
at org.geotools.data.postgis.PostgisDataStore.buildSchema(PostgisDataStore.java:593)
at org.geotools.data.jdbc.FeatureTypeHandler.getFeatureTypeInfo(FeatureTypeHandler.java:200)
at org.geotools.data.jdbc.FeatureTypeHandler.getSchema(FeatureTypeHandler.java:168)
at org.geotools.data.jdbc.JDBC1DataStore.getSchema(JDBC1DataStore.java:388)
at org.geotools.data.jdbc.JDBC1DataStore.getFeatureReader(JDBC1DataStore.java:626)
at tigerpoly.TigerPoly.getCC(TigerPoly.java:116)
at tigerpoly.TigerPoly.main(TigerPoly.java:349)

Posted by at Mar 20, 2006 13:54
|
this is probably because you do not have permission to either (1) write to the temp directory or (2) read the files you created.
The easiest thing to try is to login as "root" - if it works, then its a "simple" permission problem that you have to track down.

Posted by dblasby at Apr 18, 2006 18:41
|
Do the errors mentioned in tiger2005fe still apply for tiger2005se?

Posted by seanasy at Jul 10, 2006 22:45
|
I'm trying to load tiger2005se and I'm running into a few issues. I'll post some infomation on the issues I'm running into once I have something substantial to share.
Sean, I'm hoping you're monitoring this article, as I can find no way to contact you directly. Perhaps we can collaborate on this? Email me at [email protected] if you're interested.
Thanks,
Daniel Ceregatti

Posted by daniel ceregatti at Jul 21, 2006 00:04
|
I had a problem with the program telling me 'You must create the poly2 table in the postgis database'. Turns out that the program was putting a carriage return as part of the module name so I simply piped the go.txt file through perl to strip off the carraige returns and execute the commands.
cat go.txt | perl -n -e 's/\r
Hope this helps.
Robert J Derr
Weatherflow, Inc.
|
The article says that it assumes you have the Tiger data loaded already. Which RT files and which layers need to be loaded?

Posted by brian_252 at Aug 29, 2006 07:14
|
OK, I was making the mistake of loading each RT file when i should have been loading them all at once by specifying the directory. I asked my first question because my database during this load was growing to huge capacities.

Posted by brian_252 at Aug 29, 2006 12:06
|
I was able to run TigerPoly.java on tiger2005se with GIJ.
Apparently GIJ 4.1.2 doesn't have support for java.util.regex.Pattern. So i just hardcoded my params. I included schema since my work is in the tiger schema.
Apparently JAI adepends on nonfree software. At least i couldn't find com.sun.media.jai.codec.SeekableStream. I downloaded the source for GeoTools 2.2.0. I editted a class named Hints to remove it's static dependency on JAI. Just commented out the one line.
GeoTools depens on Maven which doesn't work with GIJ, but you can just compile Hints.java manually. Three class files are produced. Hints, Hints$Key, and Utilities. Put them in gt2-referencing-2.2.0.jar.
I was getting this exception:
IllegalArgumentException: "FeatureReader allready produces contents with the correct schema"
from JDBC1DataStore.getFeatureReader( query, trans ) calling ReTypeFeatureReader(). That was occurring because (requestedNames.length < propertyNames.length). If you add "module" to requestedNames (called ps) for completechain, polychainlink,and pip, then propertyNames is set to requestedNames earlier and you avoid the retyping.

Posted by brian_252 at Sep 03, 2006 13:49
|
A few notes on running this process with tiger2006se. (Yeah, that's 2006 -- last TIGER evah!)
I encountered a few data problems, but not all those above.
Notably, I got a "poly has 0 pips!" error. To resolve it, I modified TigerPoly.java as follows:
Recompile TigerPoly.java and run the offending modules again. It reported these polys to be in error:
TGR16039: 4882
TGR53031: 6599
The following SQL should fix those modules.
Run those modules again and it should succeed.
Finally, I had problems with Guam which were solved according to the above procedure.

Posted by tcarobruce at Jun 26, 2007 18:20
|
Problems here with Postgis 1.2.3 on Postgres 8.2.4: You must create the poly2 table in the postgis database:
create table poly2 (the_geom geometry, polyid numeric(10,0), module char(8)) with oids;
insert into geometry_columns values ('','public','poly2','the_geom',2,1,'POLYGON');
But I do have a poly2 table... Table "public.poly2"
Column | Type | Modifiers
--------------------------------
the_geom | geometry |
polyid | numeric(10,0) |
module | character(8) |
I'm thinking the version of GeoTools included in tigerpolygoninformation.zip doesn't play nice with this Postgres/PostGIS version, but unfortunately the newer GeoTools versions have significant API changes.
Any ideas?

Posted by bergamini at Sep 25, 2007 15:58
|
Here's the stack trace for the exception leading to the "You must create the poly2 table" message:
org.geotools.data.SchemaNotFoundException: Feature type could not be found for poly2
at org.geotools.data.memory.MemoryDataStore.getSchema(MemoryDataStore.java:271)
at org.geotools.data.memory.MemoryDataStore$1.<init>(MemoryDataStore.java:320)
at org.geotools.data.memory.MemoryDataStore.getFeatureReader(MemoryDataStore.java:319)
at tigerpoly.TigerPoly.write(TigerPoly.java:424)
at tigerpoly.TigerPoly.main(TigerPoly.java:381)

Posted by bergamini at Sep 25, 2007 16:09
|
|